﻿using System;
abstract class product
{
    public abstract double getS();
    public abstract bool legal();
}
class rectangle: product
{
    public double x, y;
    public rectangle(double x, double y)
    {
        this.x = x;
        this.y = y;
    }

    public override double getS()
    {
        return x * y;
    }
    public override bool legal()
    {
        return (x>0&&y>0);
    }
}
class square : product
{
    public double x;
    public square(double x)
    {
        this.x = x;
    }

    public override double getS()
    {
        return x * x;
    }
    public override bool legal()
    {
        return x > 0;
    }
}
class triangle : product
{
    public double x, y, z;
    triangle(double x, double y, double z)
    {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    public override double getS() {
        double p = (x + y + z) / 2;
        return Math.Sqrt(p*(p-x)*(p-y)*(p-z));
    }
    public override bool legal()
    {
        return x>0 && y>0 && z>0&&x+y>z&&x+z>y&&y+z>x;
    }
    class Factory
    {
        public static  product GetProduct(string arg)
        {
            product product = null;
            if (arg.Equals("retangle")) {
                Console.WriteLine("输入长方形的长：");
                double a=double.Parse(Console.ReadLine());
                Console.WriteLine("输入长方形的宽：");
                double b = double.Parse(Console.ReadLine());
                product = new rectangle(a, b);
            }
            else if (arg.Equals("square"))
            {
                Console.WriteLine("输入正方形的长：");
                double a = double.Parse(Console.ReadLine());
                product = new square(a);

            }
            else if (arg.Equals("triangle"))
            {
                Console.WriteLine("输入边1：");
                double a = double.Parse(Console.ReadLine());
                Console.WriteLine("输入边2：");
                double b = double.Parse(Console.ReadLine());
                Console.WriteLine("输入边3：");
                double c= double.Parse(Console.ReadLine());
                
                product = new triangle(a,b,c);
            }
            return product;
        }
    }
    class main
    {
        public static void Main()
        {
            double s_sum = 0;
            for(int i = 0; i < 10; i++)
            {
                product product;
                Console.WriteLine("请输入retangle||square||triangle");
                string s = Console.ReadLine();
                product=Factory.GetProduct(s);
                s_sum += product.getS();
            }
            Console.WriteLine("面积之和为" + s_sum);
        }
    }
}